package com.wy.service.impl;

import com.wy.dao.InterfaceLogDao;
import com.wy.model.InterfaceLog;
import com.wy.service.InterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
* @描述
* @创建人 wangyue
* @创建时间2019/12/216:28
*/
@Service
public class InterfaceLogServiceImpl implements InterfaceLogService{

@Autowired
private InterfaceLogDao interfaceLogDao;

@Override
public List<InterfaceLog> list(InterfaceLog interfaceLog) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
    interfaceLog.setYyyymm(sdf.format(new Date()));
    return interfaceLogDao.list(interfaceLog);
    }

    @Override
    public InterfaceLog getById(String id) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return interfaceLogDao.getById(id,sdf.format(new Date()));
    }

    @Override
    public void insert(InterfaceLog interfaceLog) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        interfaceLog.setYyyymm(sdf.format(new Date()));
         interfaceLogDao.insert(interfaceLog);
    }

    @Override
    public void update(InterfaceLog interfaceLog) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        interfaceLog.setYyyymm(sdf.format(new Date()));
        interfaceLogDao.update(interfaceLog);
    }

    @Override
    public int deletebth(String[] id) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
    return interfaceLogDao.deletebth(id,sdf.format(new Date()));
    }
    //定时任务，提前创建下个月的表
    @Scheduled(cron = "10 0 17 17 * ? ")
    public void create(){
       //获取当前月份的下一个月份
        Calendar calendar = Calendar.getInstance();//java日期类当前日期
        calendar.add(Calendar.MONTH, 1);//月份+1
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        String yyyymm=sdf.format(calendar.getTime());
        interfaceLogDao.create(yyyymm);
    }
}
